package com.colaps.gifts;


import java.util.List;

import com.colaps.gifts.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import android.widget.TextView;

public class ContactListAdapter extends ArrayAdapter<ContactInfo> {
    private final Activity activity;
    private final List<ContactInfo> stocks;

    public ContactListAdapter(Activity activity, List<ContactInfo> objects) {
        super(activity, R.layout.filacontacto, objects);
        this.activity = activity;
        this.stocks = objects;
    }
    
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View rowView = convertView;
        ContactStockView sv = null;
        if (rowView == null) {
            // Get a new instance of the row layout view
            LayoutInflater inflater = activity.getLayoutInflater();
            rowView = inflater.inflate(R.layout.filacontacto, null);

            // Hold the view objects in an object,
            // so they don't need to be re-fetched
            sv = new ContactStockView();
            sv.name = (TextView) rowView.findViewById(R.id.contact_name);
            sv.number = (TextView) rowView.findViewById(R.id.contact_number);

            
            // Cache the view objects in the tag,
            // so they can be re-accessed later
            rowView.setTag(sv);
        } else {
            sv = (ContactStockView) rowView.getTag();
        }
        // Transfer the stock data from the data object
        // to the view objects
        ContactInfo currentStock = (ContactInfo) stocks.get(position);
        sv.name.setText(currentStock.getDisplayName());
        sv.number.setText(currentStock.getPhoneNumber());
        

        return rowView;
    }
    
    protected static class ContactStockView {
        protected TextView name;
        protected TextView number;
	
    }
}
